<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
			<el-form :inline="true" :model="filters">

				<el-form-item label="运营商" prop="operatoruid">
					<el-select v-model="filters.operatoruid" filterable clearable  placeholder="请选择运营商">
						<el-option value="0" label="全部">全部</el-option>
						<el-option
								v-for="item in operator"
								:key="item.operatoruid"
								:label="item.operatorname"
								:value="item.operatoruid">
						</el-option>
					</el-select>
				</el-form-item>

				<el-form-item label="省份" prop="provinceuuid">
					<el-select v-model="filters.provinceuuid" filterable :filter-method="selectfilter" clearable placeholder="请选择省份">
						<el-option value="0" label="全部">全部</el-option>
						<el-option
								v-for="item in info"
								:key="item.provinceuuid"
								:label="item.provincename"
								:value="item.provinceuuid">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="城市">
					<el-select v-model="filters.cityName" filterable clearable placeholder="请选择地市">
						<el-option
								v-for="item in infoFilters"
								:key="item.cityName"
								:label="item.cityName"
								:value="item.cityName">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="业务类型" prop="busuuid"  >
					<el-select v-model="filters.busuuid" filterable clearable placeholder="请选择业务类型"   >
						<el-option value="0" label="全部" >全部</el-option>
						<el-option
								v-for="item in bus"
								:key="item.busuuid"
								:label="item.busname"
								:value="item.busuuid">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="供货商" prop="useruuid" >
					<el-select v-model="filters.useruuid" clearable placeholder="请选择供货商" filterable  @change="userChange"  >
						<el-option value="0" label="全部" >全部</el-option>
						<el-option v-if="usersUp && usersUp.length > 0"
								v-for="item in usersUp"
								:key="item.user.useruuid"
								:label="item.user.username"
								:value="item.user.useruuid">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="产品状态" prop="validity">
					<el-select v-model="filters.status" clearable placeholder="请选择产品状态">
						<el-option value="" label="全部">全部</el-option>
						<el-option value="2" label="禁用">禁用</el-option>
						<el-option value="1" label="正常">正常</el-option>
					</el-select>
				</el-form-item>
<!--				<el-form-item label="有效期" prop="validity">-->
<!--					<el-select v-model="filters.validity" placeholder="请选择运有效期">-->
<!--						<el-option value="0" label="全部">全部</el-option>-->
<!--						<el-option value="1" label="30天">30天</el-option>-->
<!--						<el-option value="2" label="当月">当月</el-option>-->
<!--					</el-select>-->
<!--				</el-form-item>-->
				<el-form-item>
					<el-input v-model="filters.productCode" clearable placeholder="产品编码"></el-input>
				</el-form-item>
				<el-form-item>
<!--					<el-input v-model="filters.upfacevalue" clearable placeholder="面值"></el-input>-->
					<el-select v-model="filters.upfacevalue" clearable filterable collapse-tags  placeholder="请面值">
						<el-option value="0" label="全部">全部</el-option>
						<el-option
								v-for="item in downfacevalues"
								:key="item.id"
								:label="item.id"
								:value="item.id">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" v-on:click="findPageProduct">查询</el-button>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="exportUpProduct">导出</el-button>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="handleAdd">新增</el-button>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" @click="handleBatchEdit">批量修改</el-button>
				</el-form-item>
<!--				<el-form-item>-->
<!--					<el-button type="primary" @click="handleBatchOpen">批量开启产品</el-button>-->
<!--				</el-form-item>-->
<!--				<el-form-item>-->
<!--					<el-button type="primary" @click="handleBatchClose">批量禁用产品</el-button>-->
<!--				</el-form-item>-->
<!--				<el-form-item>-->
<!--					<el-button type="primary"  @click="handleBatchPhoneEdit">批量修改话费</el-button>-->
<!--				</el-form-item>-->
			</el-form>
		</el-col>

		<!--列表-->
		<el-table :data="products" highlight-current-row v-loading="listLoading" max-height="620" border style="width: 100%;">
			<el-table-column type="index" width="80"   label="编号">
			</el-table-column>
			<el-table-column prop="operators.operatorname" width="100px" label="运营商" >
			</el-table-column>
			<el-table-column prop="provincialInformation.provincename" label="省份"    >
			</el-table-column>
			<el-table-column prop="cityName" label="地市"    >
			</el-table-column>
			<el-table-column prop="businessType.busname" width="110px"  label="业务类型" show-overflow-tooltip  >
			</el-table-column>
			<el-table-column prop="user.username" width="130px"  label="供货商" show-overflow-tooltip >
			</el-table-column>
			<el-table-column prop="productCode" label="产品编码" width="100px" show-overflow-tooltip >
			</el-table-column>
			<el-table-column prop="productName"  width="110px" label="产品名称" show-overflow-tooltip>
			</el-table-column>
			<el-table-column prop="price"  width="110px" label="原价">
			</el-table-column>
			<el-table-column prop="upfacevalue"  width="120px" label="面值" :formatter="productType">
			</el-table-column>

			<el-table-column prop="discount" label="实际折扣"  width="100px"    >
			</el-table-column>
			<el-table-column prop="discountAmount" label="实际金额"  width="110px"    >
			</el-table-column>
<!--			<el-table-column prop="deduct" label="扣款折扣"  width="100px"    >-->
<!--			</el-table-column>-->
<!--			<el-table-column prop="deductAmount" label="扣款金额"  width="110px"    >-->
<!--			</el-table-column>-->
<!--			<el-table-column prop="validity" label="有效期":formatter="fastchargevalidity" >-->
<!--			</el-table-column>-->
			<el-table-column prop="status" label="状态"   :formatter="status"  >
			</el-table-column>
			<el-table-column prop="remark" label="备注"   >
			</el-table-column>
<!--			<el-table-column label="压单" >-->
<!--				<template scope="scope">-->
<!--					<el-switch-->
<!--							v-model="scope.row.pressOrder"-->
<!--							active-text=""-->
<!--							@change="changePressOrder(scope.row)"-->
<!--							inactive-text="">-->
<!--					</el-switch>-->
<!--				</template>-->
<!--			</el-table-column>-->
<!--			<el-table-column label="人工" >-->
<!--				<template scope="scope">-->
<!--					<el-switch-->
<!--							v-model="scope.row.artificial"-->
<!--							@change="changeArtificial(scope.row)"-->
<!--							active-text=""-->
<!--							inactive-text="">-->
<!--					</el-switch>-->
<!--				</template>-->
<!--			</el-table-column>-->
			<el-table-column label="操作" width="200"  fixed="right">
				<template scope="scope">
					<el-button size="small" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
					<el-button size="small" @click="handleEnable(scope.$index, scope.row)">{{scope.row.status == 2 ? '启用' : '禁用'}}</el-button>
					<el-button size="small" @click="deleteEnable(scope.$index, scope.row)">
						删除
					</el-button>
				</template>
			</el-table-column>
		</el-table>

		<!--工具条-->
		<el-pagination
				@current-change="handleCurrentChange"
				@size-change="handleSizeChange"
				layout="total,sizes,prev, pager, next"
				:total="total">
		</el-pagination>
		<!--编辑界面-->
		<el-dialog title="编辑供货商产品" v-model="editFormVisible" :close-on-click-modal="false">
			<el-form :model="editForm" label-width="100px"  :inline="true"  :rules="editFormRules" ref="editForm">
				<el-form-item label="运营商" prop="operatoruid"  >
					<el-select v-model="editForm.operatoruid" filterable placeholder="请选择运营商"  >
						<el-option
								v-for="item in operator"
								:key="item.operatoruid"
								:label="item.operatorname"
								:value="item.operatoruid">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="省份" prop="provinceuuid"  >
					<el-select v-model="editForm.provinceuuid" filterable @change="selectCity(editForm.provinceuuid)" placeholder="请选择省份" >
						<el-option
								v-for="item in info"
								:key="item.provinceuuid"
								:label="item.provincename"
								:value="item.provinceuuid">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="城市">
					<el-select v-model="editForm.cityName" filterable clearable placeholder="请选择地市">
						<el-option
								v-for="item in citys"
								:key="item.cityName"
								:label="item.cityName"
								:value="item.cityName">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="业务类型" prop="busuuid"  >
					<el-select v-model="editForm.busuuid" filterable placeholder="请选择业务类型"   >
						<el-option
								v-for="item in bus"
								:key="item.busuuid"
								:label="item.busname"
								:value="item.busuuid">
						</el-option>
					</el-select>
				</el-form-item>

				<el-form-item label="供货商" prop="useruuid" >
					<el-select v-model="editForm.useruuid" filterable placeholder="请选择供货商"   >
						<el-option
								v-for="item in usersUp"
								:key="item.user.useruuid"
								:label="item.user.username"
								:value="item.user.useruuid">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="产品名称" prop="productName">
					<el-input v-model="editForm.productName" placeholder="请输入产品名称"></el-input>
				</el-form-item>
				<el-form-item label="产品编码" prop="productCode" >
					<el-input v-model="editForm.productCode" placeholder="请输入产品编码"></el-input>
				</el-form-item>
				<el-form-item label="原价" prop="price">
					<el-input v-model="editForm.price" v-on:input="discountChangeEdit"></el-input>
				</el-form-item>
				<el-form-item label="面值"  prop="upfacevalue">
					<el-input v-model="editForm.upfacevalue" placeholder="如 1024 表示 1024M流量"  ></el-input>
				</el-form-item>
				<el-form-item label="折扣"  prop="discount">
					<el-input v-model="editForm.discount"   v-on:input="discountChangeEdit"  ></el-input>
				</el-form-item>
				<el-form-item label="折扣金额" prop="discount">
					<el-input v-model="editForm.discountAmount" :disabled="true"></el-input>
				</el-form-item>
<!--				<el-form-item label="有效期" prop="validity">-->
<!--					<el-select v-model="editForm.validity" placeholder="请选择运有效期">-->
<!--						<el-option value="0" label="全部">全部</el-option>-->
<!--						<el-option value="1" label="30天">30天</el-option>-->
<!--						<el-option value="2" label="当月">当月</el-option>-->
<!--					</el-select>-->
<!--				</el-form-item>-->

				<el-form-item label="备注">
					<el-input type="textarea" v-model="editForm.remark"></el-input>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="editFormVisible = false">取消</el-button>
				<el-button type="primary" @click.native="editSubmit" :loading="editLoading">提交</el-button>
			</div>
		</el-dialog>

		<!--批量新增界面-->
		<el-dialog title="批量新增供货商产品" width="100%" v-model="addFormVisible" :close-on-click-modal="false">
			<el-form :model="addForm" label-width="100px" :inline="true"  :rules="addFormRules" ref="addForm">
				<el-form-item label="运营商" prop="operatoruid"  >
					<el-select v-model="addForm.operatoruid" filterable @change="changeOperator" placeholder="请选择运营商"    >
						<el-option
								v-for="item in operator"
								:key="item.operatoruid"
								:label="item.operatorname"
								:value="item.operatoruid">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="省份" prop="provinceuuid"  >
					<el-select v-model="addForm.provinceuuid" filterable @change="selectCity(addForm.provinceuuid)" placeholder="请选择省份" >
						<el-option
								v-for="item in info"
								:key="item.provinceuuid"
								:label="item.provincename"
								:value="item.provinceuuid">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="城市">
					<el-select v-model="addForm.cityName" filterable clearable placeholder="请选择地市">
						<el-option
								v-for="item in citys"
								:key="item.cityName"
								:label="item.cityName"
								:value="item.cityName">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="业务类型" prop="busuuid"  >
					<el-select v-model="addForm.busuuid" filterable placeholder="请选择业务类型"   >
						<el-option
								v-for="item in bus"
								:key="item.busuuid"
								:label="item.busname"
								:value="item.busuuid">
						</el-option>
					</el-select>
				</el-form-item>

				<el-form-item label="供货商" prop="useruuid" >
					<el-select v-model="addForm.useruuid" filterable placeholder="请选择供货商"   >
						<el-option
								v-for="item in usersUp"
								:key="item.user.useruuid"
								:label="item.user.username"
								:value="item.user.useruuid">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="折扣"  prop="unitPrice">
					<el-input v-model="addForm.unitPrice" style="width: 216px;" v-on:input="discountChangeAdd"></el-input>
				</el-form-item>
<!--				<el-form-item label="流量类型" label-width="120px">-->
<!--					<el-radio-group v-model="addForm.packagetype">-->
<!--						<el-radio  :label="1">流量池</el-radio>-->
<!--						<el-radio  :label="0">包型</el-radio>-->
<!--					</el-radio-group>-->
<!--				</el-form-item>-->
				<el-form-item label="话费面值" prop="channe">
					<el-checkbox-group v-model="addForm.channe"   @change="handleCheckedChange">
						<el-checkbox v-for="channel in channels" :label="channel.basePrice" :key="channel.baseId">{{channel.baseName}}</el-checkbox>
					</el-checkbox-group>
				</el-form-item>

				<el-form-item label="压单" >
					<el-switch
							v-model="addForm.pressOrder"
							@change="changeBatchPressOrder(addForm)"
							active-text=""
							inactive-text="">
					</el-switch>
				</el-form-item>

				<el-form-item label="人工" >
					<el-switch
							v-model="addForm.artificial"
							active-text="" @change="changeBatchArtificial(addForm)"
							inactive-text="">
					</el-switch>
				</el-form-item>


				<el-table :data="setProducts"  show-overflow-tooltip="true" max-height="620"  @cell-click="cellclick" @cell-mouse-leave="cellmouseleave"  border style="width: 100%;">
					<el-table-column type="index" width="80" label="编号">
					</el-table-column>
					<el-table-column prop="productName" label="产品名称" show-overflow-tooltip  width="130px">
					</el-table-column>
					<el-table-column prop="productCode"  width="100px" label="产品编码" >
					</el-table-column>
					<el-table-column prop="upfacevalue"  width="100px" label="面值" :formatter="upfacevalueProduct" >
					</el-table-column>
					<el-table-column prop="price"  width="110px" label="原价"   :formatter="upfacevalueprice">
					</el-table-column>
					<el-table-column prop="discount"  width="100px" label="折扣">
					</el-table-column>
					<el-table-column prop="discountAmount"  width="160px" label="成本金额">
					</el-table-column>
				</el-table>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="addFormVisible = false">取消</el-button>
				<el-button type="primary" @click.native="addUpProduct" :loading="addLoading">提交</el-button>
			</div>
		</el-dialog>

		<!--批量编辑界面-->
		<el-dialog title="批量编辑供货商产品" width="100%" v-model="batchFormVisible" :close-on-click-modal="false">
			<el-form :model="batchForm" label-width="100px" :inline="true"  :rules="batchFormRules" ref="batchForm">
				<el-form-item label="运营商" prop="operatoruid"  >
					<el-select v-model="batchForm.operatoruid" filterable @change="changeOperator" placeholder="请选择运营商"    >
						<el-option
								v-for="item in operator"
								:key="item.operatoruid"
								:label="item.operatorname"
								:value="item.operatoruid">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="省份" prop="provinceuuid"  >
					<el-select v-model="batchForm.provinceuuid" filterable  @change="selectCity(batchForm.provinceuuid)" placeholder="请选择省份" >
						<el-option
								v-for="item in info"
								:key="item.provinceuuid"
								:label="item.provincename"
								:value="item.provinceuuid">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="城市">
					<el-select v-model="batchForm.cityName" filterable clearable placeholder="请选择地市">
						<el-option
								v-for="item in citys"
								:key="item.cityName"
								:label="item.cityName"
								:value="item.cityName">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="业务类型" prop="busuuid"  >
					<el-select v-model="batchForm.busuuid" filterable placeholder="请选择业务类型"   >
						<el-option
								v-for="item in bus"
								:key="item.busuuid"
								:label="item.busname"
								:value="item.busuuid">
						</el-option>
					</el-select>
				</el-form-item>

				<el-form-item label="供货商" prop="useruuid" >
					<el-select v-model="batchForm.useruuid" filterable placeholder="请选择供货商"   >
						<el-option
								v-for="item in usersUp"
								:key="item.user.useruuid"
								:label="item.user.username"
								:value="item.user.useruuid">
						</el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="折扣"  prop="unitPrice">
					<el-input v-model="batchForm.unitPrice" v-on:input="discountBatchChangeAdd"></el-input>
				</el-form-item>
<!--				<el-form-item label="流量类型" label-width="120px">-->
<!--					<el-radio-group v-model="batchForm.packagetype">-->
<!--						<el-radio  :label="1">流量池</el-radio>-->
<!--						<el-radio  :label="0">包型</el-radio>-->
<!--					</el-radio-group>-->
<!--				</el-form-item>-->
				<el-form-item label="话费包型" prop="channe">
					<el-checkbox-group v-model="batchForm.channe" @change="handleBatchCheckedChange">
						<el-checkbox v-for="channel in channels" :label="channel.basePrice" :key="channel.baseId">{{channel.baseName}}</el-checkbox>
					</el-checkbox-group>
				</el-form-item>

<!--				<el-form-item label="折扣"  prop="unitPrice">-->
<!--					<el-input v-model="batchForm.unitPrice" v-on:input="discountBatchChangeAdd"></el-input>-->
<!--				</el-form-item>-->

				<el-form-item label="压单" >
						<el-switch
								v-model="batchForm.pressOrder"
								@change="changeBatchPressOrder(batchForm)"
								active-text=""
								inactive-text="">
						</el-switch>
				</el-form-item>

				<el-form-item label="人工" >
						<el-switch
								v-model="batchForm.artificial"
								active-text="" @change="changeBatchArtificial(batchForm)"
								inactive-text="">
						</el-switch>
				</el-form-item>


				<el-table :data="setBatchProducts"  show-overflow-tooltip="true" max-height="620"  @cell-click="batchCellclick" @cell-mouse-leave="batchCellmouseleave"  border style="width: 100%;">
					<el-table-column type="index" width="80" label="编号">
					</el-table-column>
					<el-table-column prop="productName" label="产品名称" show-overflow-tooltip width="130px" :formatter="updateProductName(batchForm)">
					</el-table-column>
					<el-table-column prop="productCode"  width="100px" label="产品编码" show-overflow-tooltip   >
					</el-table-column>
					<el-table-column prop="upfacevalue"  width="100px" label="面值" :formatter="upfacevalueProduct" >
					</el-table-column>
					<el-table-column prop="price"  width="110px" label="原价" :formatter="upfacevalueprice">
					</el-table-column>
					<el-table-column prop="discount"  width="100px" label="折扣">
					</el-table-column>
					<el-table-column prop="discountAmount"  label="成本金额">
					</el-table-column>
				</el-table>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="batchFormVisible = false">取消</el-button>
				<el-button type="primary" @click.native="editBatchUpProduct" :loading="addLoading">提交</el-button>
			</div>
		</el-dialog>

	</section>
</template>

<script>
	import util from '../../common/js/util'
	//import NProgress from 'nprogress'
	import {
		findPageProduct,
		findOpeProBusShop,
		addBatchUpProduct,
		findBatchUpProduct,
		editBatchUpProduct,
		findByProvince,
		findByChannel,
		updateUpProduct,
		findOneUpProduct,
		findAllUpShopInfo,
		productEnable,
		upfindlist,
		exportUpProduct,
		editBatchPhoneUpProduct,
		findAllCity,
		updateProductArtificial,
		updateProductPressOrder,
		handleBatchStatus, deleteUpProduct, findAllChannel
	} from '../../api/api';
    import ElOption from "../../../node_modules/element-ui/packages/select/src/option.vue";

	export default {
        components: {ElOption},
        data() {
			return {
				filters: {
					name: '',
                    busuuid:'',
                    useruuid:'',
                    productCode:'',
                    provinceuuid:'',
                    operatoruid:'',
                    validity:'',
					cityName:'',
					upfacevalue:'',
					status:''
				},
                products: [],
                setProducts:[],
                setBatchProducts:[],
                setBatchPhoneProducts:[],
				downfacevalues:[],
                channels:[],
				infoFilters:[],
				citys:[],
                total: 0,
                start:0,
                pageSize:10,
				listLoading: false,
				editFormVisible: false,//编辑界面是否显示
				editLoading: false,
				editFormRules: {
                    operatoruid: [
                        { required: true, message: '请选择运营商', trigger: 'blur' }
                    ],
                    provinceuuid: [
                        { required: true, message: '请选择省份', trigger: 'blur' }
                    ],
                    busuuid: [
                        { required: true, message: '请选择业务类型', trigger: 'blur' }
                    ],
                    useruuid: [
                        { required: true, message: '请选择渠道商', trigger: 'blur' }
                    ],
                    upfacevalue :[
                        { required: true, message: '请输入面值,如果是话费则是对应的充值原价,如果是流量则是xxM', trigger: 'blur' }
                    ],
                    productCode :[
                        { required: true, message: '请输入产品名称', trigger: 'blur' }
                    ],
                    discount :[
                        { required: true, message: '请输入折扣', trigger: 'blur' },
                        {min: 1, max: 8, message: '长度在 1 到 3 个字符', trigger: 'blur'},
                    ],
                    fastchargetype :[
                        { required: true, message: '请选择快慢充类型', trigger: 'blur' }
                    ],price:[
                        {required: true, message: '请输入原价', trigger: 'blur'}
                    ],productName:[
                        {required: true, message: '请输入产品名称', trigger: 'blur'}
                    ]
				},
				//编辑界面数据
				editForm: {
                    operatoruid: '',
                    provinceuuid: '',
					cityName:'',
                    busuuid: '',
                    user: {useruuid:''},
                    productCode: '',
                    upfacevalue: '',
                    discount: '',
                    fastchargetype: '1',
                    remark: '',
                    useruuid:'',
                    upfailnum:1,
                    uptimeinterva:1,
                    upprouuid:'',
                    price:'0',
                    discountAmount:'',
                    validity:'1',
                    productName:''
				},

				addFormVisible: false,//新增界面是否显示
				addLoading: false,
				addFormRules: {
                    operatoruid: [
						{ required: true, message: '请选择运营商', trigger: 'blur' }
					],
                    provinceuuid: [
                        { required: true, message: '请选择省份', trigger: 'blur' }
                    ],
                    busuuid: [
                        { required: true, message: '请选择业务类型', trigger: 'blur' }
                    ],
                    useruuid: [
                        { required: true, message: '请选择渠道商', trigger: 'blur' }
                    ],
                    upfacevalue :[
                        { required: true, message: '请输入面值,如果是话费则是对应的充值原价,如果是流量则是xxM', trigger: 'blur' }
                    ],
                    productCode :[
                        { required: true, message: '请输入产品名称', trigger: 'blur' }
                    ],
                    discount :[
                        { required: true, message: '请输入折扣', trigger: 'blur' },
                        {min: 1, max: 8, message: '长度在 1 到 3 个字符', trigger: 'blur'},
                    ],
                    fastchargetype :[
                        { required: true, message: '请选择快慢充类型', trigger: 'blur' }
                    ],price:[
                        {required: true, message: '请输入原价', trigger: 'blur'}
                    ],unitPrice: [
                        {required: true, message: '请输入单价', trigger: 'blur'},
                    ]
				},
				//新增界面数据
				addForm: {
                    operatoruid: '',
                    provinceuuid: '',
                    busuuid: '',
					cityName:'',
                    user: {useruuid:''},
                    productCode: '',
                    upfacevalue: '',
                    discount: '1',
                    fastchargetype: '1',
                    remark: '',
                    useruuid:'',
                    upfailnum:1,
                    uptimeinterva:1,
                    price:'0',
                    discountAmount:'',
                    packagetype:1,
                    unitPrice:"1",
					channe:[],
					pressOrder:false,
					artificial:false
				},
				//下拉数据
				operator :[],
             	info:[],
                bus:[],
                usersUp:[],
				ups:[],
                batchFormVisible: false,//新增界面是否显示
                batchLoading: false,
                batchFormRules: {
                    operatoruid: [
                        { required: true, message: '请选择运营商', trigger: 'blur' }
                    ],
                    provinceuuid: [
                        { required: true, message: '请选择省份', trigger: 'blur' }
                    ],
                    busuuid: [
                        { required: true, message: '请选择业务类型', trigger: 'blur' }
                    ],
                    useruuid: [
                        { required: true, message: '请选择渠道商', trigger: 'blur' }
                    ],
                    upfacevalue :[
                        { required: true, message: '请输入面值,如果是话费则是对应的充值原价,如果是流量则是xxM', trigger: 'blur' }
                    ],
                    productCode :[
                        { required: true, message: '请输入产品名称', trigger: 'blur' }
                    ],
                    discount :[
                        { required: true, message: '请输入折扣', trigger: 'blur' },
                        {min: 1, max: 8, message: '长度在 1 到 3 个字符', trigger: 'blur'},
                    ],
                    fastchargetype :[
                        { required: true, message: '请选择快慢充类型', trigger: 'blur' }
                    ],price:[
                        {required: true, message: '请输入原价', trigger: 'blur'}
                    ],unitPrice: [
                        {required: true, message: '请输入单价', trigger: 'blur'},
                    ]
                },
                //新增界面数据
                batchForm: {
                    operatoruid: '',
					cityName:'',
                    provinceuuid: '',
                    busuuid: '',
                    user: {useruuid:''},
                    productCode: '',
                    upfacevalue: '',
                    discount: '1',
                    fastchargetype: '1',
                    remark: '',
                    useruuid:'',
                    upfailnum:1,
                    uptimeinterva:1,
                    price:'0',
                    discountAmount:'',
                    packagetype:1,
                    unitPrice:"1",
                    channe:[],
					pressOrder:false,
					artificial:false
                },

                batchPhoneFormVisible: false,
                batchPhoneLoading: false,
                batchPhoneFormRules: {
                    operatoruid: [
                        { required: true, message: '请选择运营商', trigger: 'blur' }
                    ],
                    provinceuuid: [
                        { required: true, message: '请选择省份', trigger: 'blur' }
                    ],
                    busuuid: [
                        { required: true, message: '请选择业务类型', trigger: 'blur' }
                    ],
                    useruuid: [
                        { required: true, message: '请选择渠道商', trigger: 'blur' }
                    ],
//                    discount :[
//                        { required: true, message: '请输入折扣', trigger: 'blur' },
//                        {min: 1, max: 8, message: '长度在 1 到 3 个字符', trigger: 'blur'},
//                    ],
//                    deduct :[
//                        { required: true, message: '请输入折扣', trigger: 'blur' },
//                        {min: 1, max: 8, message: '长度在 1 到 3 个字符', trigger: 'blur'},
//                    ],
                },
                //新增界面数据
                batchPhoneForm: {
                    operatoruid: '',
                    provinceuuid: '',
                    busuuid: '',
					cityName:'',
                    user: {useruuid:''},
                    productCode: '',
                    upfacevalue: '',
                    discount: '1',
                    deduct:'1',
                    fastchargetype: '1',
                    remark: '',
                    useruuid:'',
                    upfailnum:1,
                    uptimeinterva:1,
                    price:'0',
                    discountAmount:'',
                    packagetype:1,
                    unitPrice:'1',
                    channe:[]
                },
			}
		},
		methods: {
            fastchargevalidity:function(row, column){
                return (row.validity === "1") ? "30天" : (row.validity === "2") ?  "当月" : "未知";
            },
            upfacevalueprice:function(row, column){
				return row.price+"元";
            },
            upfacevalueProduct:function(row, column){
                return row.upfacevalue+"元";
			},
			updateProductName(row){

			},
            productType: function (row, column) {
                return (row.businessType.busname == "手机") ? (row.upfacevalue + '话费') : ( row.businessType.busname == "固话") ?  (row.upfacevalue + '话费') :(row.upfacevalue + '话费');
            },
            fastchargetype: function (row, column) {
				return row.fastchargetype == 1 ? '快充' : row.fastchargetype == 0 ? '慢充' : '未知';
			},
            status: function (row, column) {
                return row.status == "1" ? '正常' : row.status == "0" ? '删除' :  row.status == "2"  ? "禁用" :  '未知';
            },

            findPageProduct() {
				let para = {
                    start: this.start,
                    pageSize:this.pageSize,
                    provinceuuid:this.filters.provinceuuid == "0" ? "" :this.filters.provinceuuid ,
                    operatoruid:this.filters.operatoruid == "0" ? "" :this.filters.operatoruid ,
                    busuuid:this.filters.busuuid == "0" ? "" :this.filters.busuuid ,
                    useruuid:this.filters.useruuid == "0" ? "" :this.filters.useruuid ,
                    productCode:this.filters.productCode ,
                    fastchargetype:'',
                    upfacevalue:this.filters.upfacevalue,
                    validity:this.filters.validity == "0" ? "" :this.filters.validity,
					cityName:this.filters.cityName,
					status: this.filters.status == "0" ? "" :this.filters.status
                };
				this.listLoading = true;
                findPageProduct(para).then((datas) => {
                    let { message, code, data } = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else if(data && data.result) {
                        this.products = data.result;
                        this.total = data.totalCount;
                    }
					this.listLoading = false;
				});
			},
            exportUpProduct(){
                let para = {
                    provinceuuid: this.filters.provinceuuid == "0" ? "" :this.filters.provinceuuid  ,
                    operatoruid:this.filters.operatoruid == "0" ? "" :this.filters.operatoruid ,
                    busuuid:this.filters.busuuid == "0" ? "" :this.filters.busuuid ,
                    useruuid:this.filters.useruuid == "0" ? "" :this.filters.useruuid ,
                    productCode:this.filters.productCode ,
                    fastchargetype:'',
                    upfacevalue:''
                };
                this.listLoading = true;
                exportUpProduct(para).then((datas) => {
                    let {message, code, data} = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        window.open(data.path);
                    }
                    this.listLoading = false;
                });
			},
            discountChangeAdd:function () {
//                this.addForm.discountAmount = this.addForm.discount * this.addForm.price;
				this.addProduct();
            },
            discountChangeEdit:function () {
                this.editForm.discountAmount = (this.editForm.discount * this.editForm.price).toFixed(5);
            },

			handleEnable:function(index,row){

                this.$confirm('确认更新该产品状态吗?', '提示', {
                    type: 'warning'
                }).then(() => {
                    this.listLoading = true;
                    let para = {
                        upprouuid:row.upprouuid,
                        status : row.status == "2" ? "1" : "2",
                        useruuid:util.getUserUUid()
                    };
                    productEnable(para).then((res) => {
                        this.listLoading = false;
                        //NProgress.done();
                        this.$message({
                            message: '操作成功',
                            type: 'success'
                        });
                        this.findPageProduct();
                    });
                }).catch(() => {

                });
			},
			//显示编辑界面
			handleEdit: function (index, row) {
				this.findAllCity(row.provincialInformation.provincename);
				this.editFormVisible = true;
               // this.loadBasicInfo();
                let para = {
                    upprouuid:row.upprouuid
                };
                //this.upfindlist();
                findOneUpProduct(para).then(datas =>{
                    let { message, code, data } = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        this.editForm.operatoruid = data.operators.operatoruid;
                        this.editForm.provinceuuid = data.provincialInformation.provinceuuid;
                        this.editForm.busuuid = data.businessType.busuuid;
                        this.editForm.useruuid = data.user.useruuid;
                        this.editForm.fastchargetype =  data.fastchargetype+"";
                        this.editForm.productCode = data.productCode;
                        this.editForm.upfacevalue = data.upfacevalue;
                        this.editForm.discount = data.discount;
                        this.editForm.remark = data.remark;
                        this.editForm.upprouuid = data.upprouuid;
                        this.editForm.price = data.price;
                        this.editForm.discountAmount = data.discountAmount;
                        this.editForm.validity = data.validity;
                        this.editForm.productName = data.productName;
                        this.editForm.cityName = data.cityName;
                    }
				});
			},
			loadBasicInfo:function(){
                let para = {
                    upprouuid:''
                };
                findOpeProBusShop(para).then(datas => {
                    let { message, code, data } = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        this.operator = data.operator;
                        this.info =   data.info;
                        this.bus =   data.bus;
                    }
                }).catch(e =>{
                    this.listLoading = false;
            	});

			},findAllUpShopInfo(){
				let para = {
					upprouuid:''
				};
				findAllUpShopInfo(para).then(datas => {
					let { message, code, data } = datas;
					if (code !== "0") {
						this.$message({
							message: message,
							type: 'error'
						});
					} else if(data) {
						this.usersUp =   data;
					}
				}).catch(e =>{
					this.listLoading = false;
				});
			},
			//显示新增界面
			handleAdd: function () {
				this.addFormVisible = true;
				//this.loadBasicInfo();
               	//this.upfindlist();
			},
			upfindlist:function(){
                upfindlist().then(datas =>{
                    let { message, code, data } = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        this.ups =   data;
                    }
                }).catch(e =>{
                    this.listLoading = false;
            	});
			},
			//编辑
			editSubmit: function () {
				this.$refs.editForm.validate((valid) => {
					if (valid) {
						this.$confirm('确认提交吗？', '提示', {}).then(() => {
							this.editLoading = true;
							//NProgress.start();
							let para = Object.assign({}, this.editForm);
							if(para.discount){

							}
                            updateUpProduct(para).then((datas) => {
								this.editLoading = false;
                                let { message, code, data } = datas;
                                if (code !== "0") {
                                    this.$message({
                                        message: message,
                                        type: 'error'
                                    });
                                }
								this.$refs['editForm'].resetFields();
								this.editFormVisible = false;
								this.findPageProduct();
							}).catch(e =>{
                            this.listLoading = false;
                    		});
						});
					}
				});
			},
			//新增
            addUpProduct: function () {
				if(this.setProducts != null && this.setProducts.length > 0){
					for(var i = 0 ; i < this.setProducts.length ; i++){
					    console.log(this.setProducts[i])
						if(!this.setProducts[i].productName || !this.setProducts[i].productCode){
							this.$message({
								message: "产品名称错误,请检查",
								type: 'error'
							});
							return;
						}
					}
					this.$refs.addForm.validate((valid) => {
						if (valid) {
							this.$confirm('确认提交吗？', '提示', {}).then(() => {
								this.addLoading = true;
								let para = Object.assign({}, this.addForm);
								para.products = this.setProducts;
								addBatchUpProduct(para).then((datas) => {
									this.addLoading = false;
								let { message, code, data } = datas;
								if (code !== "0") {
									this.$message({
										message: message,
										type: 'error'
									});
								}else{
									this.$message({
										message: '添加成功',
										type: 'info'
									});
								}

								this.findPageProduct();
							}).catch(e =>{
									this.listLoading = false;
							});
						});
						}
					});
				}else{
					this.$message({
						message: "请输入产品明细",
						type: 'error'
					});
				}
			}
		  , handleCurrentChange:function(val){
				this.start = val - 1;
				this.findPageProduct();
			},
            handleSizeChange:function(val){
                this.pageSize = val;
                this.findPageProduct();
            },
            infochange:function(info){
                //根据省份查询商户
                this.addForm.useruuid = '';
				let para = {
                    provinceuuid: info
				};
                findByProvince(para).then(datas =>{
                    let { message, code, data } = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        this.usersUp = data;
                    }
				}).catch(e =>{
                    this.listLoading = false;
				});
			},
            userChange:function(user){
                this.addForm.useruuid = user;
			},
            handleBatchEdit(){
                if(this.filters.operatoruid == ""){
                    this.$message({
                        message: "请先选择运营商",
                        type: 'error'
                    });
                    return;
                }
                if(this.filters.provinceuuid == ""){
                    this.$message({
                        message: "请先选择省份",
                        type: 'error'
                    });
                    return;
                }

                if(this.filters.busuuid == ""  ){
                    this.$message({
                        message: "请先选择业务类型",
                        type: 'error'
                    });
                    return;
                }
                if(this.filters.useruuid == ""){
                    this.$message({
                        message: "请先选择分销商",
                        type: 'error'
                    });
                    return;
                }
                this.setBatchProducts = [];
                this.findBatchUpProduct(this.filters.cityName);
                this.batchForm.operatoruid = this.filters.operatoruid;
                this.batchForm.provinceuuid = this.filters.provinceuuid;
                this.batchForm.busuuid = this.filters.busuuid;
                this.batchForm.useruuid = this.filters.useruuid;
                this.changeOperator(this.filters.operatoruid);
			},
            downfacevalueProduct: function (row, column) {
                return row.downfacevalue;
            },handleCheckedChange(value){
                this.addProduct();
            },
            changeOperator:function(value){
                this.addForm.channe = [];
                let para = {
                    operatoruid:value
                };
                findByChannel(para).then(datas =>{
                    let {message, code, data} = datas;
                    if (code !== "0") {
                        this.$message({
                            message: message,
                            type: 'error'
                        });
                    } else {
                        this.channels = data;
                    }
                })
            },
			cellclick:function(row, column, cell, event){
                if(column.label == "产品编码"){
                    var div = document.createElement("input");
                    div.value = cell.childNodes[0].innerHTML ;
					div.style="height:32px;width:98px;"
                    cell.replaceChild(div,cell.childNodes[0]);
                    div.focus();
				}
                if(column.label == "产品名称"){
                    var div = document.createElement("input");
                    div.value = cell.childNodes[0].innerHTML ;
                    div.style="height:32px;width:98px;"
                    cell.replaceChild(div,cell.childNodes[0]);
                    div.focus();
                }
			},cellmouseleave:function(row, column, cell, event){
                if(column.label == "产品编码" && cell.childNodes[0].tagName.toLocaleLowerCase()=='input'){
                    var div = document.createElement("div");
                    div.setAttribute("class","cell");
                    div.innerHTML = cell.childNodes[0].value;
					for(var pro in this.setProducts){
						if(this.setProducts[pro].price == row.price && row.upfacevalue == this.setProducts[pro].upfacevalue){
                            this.setProducts[pro].productCode = cell.childNodes[0].value;
						}
					}
                    cell.replaceChild(div,cell.childNodes[0]);
                }
                if(column.label == "产品名称" && cell.childNodes[0].tagName.toLocaleLowerCase()=='input'){
                    var div = document.createElement("div");
                    div.setAttribute("class","cell");
                    div.innerHTML = cell.childNodes[0].value;
                    for(var pro in this.setProducts){
                        if(this.setProducts[pro].price == row.price && row.upfacevalue == this.setProducts[pro].upfacevalue){
                            this.setProducts[pro].productName = cell.childNodes[0].value;
                        }
                    }
                    cell.replaceChild(div,cell.childNodes[0]);
                }
			},addProduct(){
                var temps = this.setProducts;
                this.setProducts = [];
                for(var cha in this.addForm.channe){
                    for(var ch in this.channels){
                        if(this.channels[ch].basePrice+"" == this.addForm.channe[cha]){
                            if(this.addForm.packagetype == 1){
                                var obj = new Object();
                                obj.price = this.channels[ch].basePrice;
                                obj.upfacevalue = this.channels[ch].flow;
                                obj.discount = (this.channels[ch].basePrice * this.addForm.unitPrice / this.channels[ch].basePrice).toFixed(5);
                                obj.discountAmount = (this.channels[ch].basePrice * this.addForm.unitPrice ).toFixed(5);
								obj.productCode = obj.upfacevalue;
								if(this.addForm.provinceuuid){
									const result = this.info.find(item => { return item.provinceuuid == this.addForm.provinceuuid });
									if(result){
										obj.productName = result.provincename + obj.upfacevalue+"元话费";
									}else{
										obj.productName = obj.upfacevalue+"元话费";
									}
								}else{
									obj.productName = obj.upfacevalue+"元话费";
								}
                                this.setProducts.push(obj);
                            }else if(this.addForm.packagetype == 0){
                                var obj = new Object();
                                obj.price = this.channels[ch].basePrice;
                                obj.upfacevalue = this.channels[ch].flow;
                                obj.discount = this.addForm.basePrice;
                                obj.discountAmount = (this.channels[ch].basePrice * this.addForm.unitPrice ).toFixed(5);
								obj.productCode = obj.upfacevalue;
								if(this.addForm.provinceuuid){
									const result = this.info.find(item => { return item.provinceuuid == this.addForm.provinceuuid });
									if(result){
										obj.productName = result.provincename + obj.upfacevalue+"元话费";
									}else{
										obj.productName = obj.upfacevalue+"元话费";
									}
								}else{
									obj.productName = obj.upfacevalue+"元话费";
								}
                                this.setProducts.push(obj);
                            }
                        }
                    }
                }
            },
            handleBatchCheckedChange(){
                this.editProduct();
			},
			discountBatchChangeAdd:function(){
                this.editProduct();
			},findBatchUpProduct(cityName){
				let  para = {
					operatoruid : this.filters.operatoruid,
					provinceuuid : this.filters.provinceuuid,
					busuuid : this.filters.busuuid,
					useruuid : this.filters.useruuid,
					cityName:cityName
				}
				findBatchUpProduct(para).then(results =>{
					let {message, code, data} = results;
					if (code !== "0") {
						this.$message({
							message: message,
							type: 'error'
						});
					}
					if(data && data.length == 0){
						this.$message({
							message: "没有找到产品,请重新选择",
							type: 'error'
						});
					}else{
						this.batchFormVisible = true;
						this.setBatchProducts = [];
						this.setBatchPhoneProducts = [];
						this.batchForm.channe = [];
						for(var pro in data){
							this.batchForm.channe.push(parseInt(data[pro].upfacevalue));
							var obj = new Object();
							obj.price = data[pro].price;
							obj.upfacevalue = data[pro].upfacevalue;
							obj.discount = data[pro].discount;
							obj.discountAmount = data[pro].discountAmount;
							obj.productCode = data[pro].productCode;
							obj.productName = data[pro].productName;
							obj.upprouuid = data[pro].upprouuid;
							obj.deduct = data[pro].discount;//扣款折扣
							obj.deductAmount = data[pro].discountAmount;
							this.batchForm.unitPrice = data[pro].discount+"";
							this.batchForm.pressOrder = data[pro].pressOrder;
							this.batchForm.artificial = data[pro].artificial;
							if(cityName){
								this.batchForm.cityName = data[pro].cityName;
							}
							this.setBatchProducts.push(obj);
							this.setBatchPhoneProducts.push(obj);
						}
						console.log(this.setBatchProducts)
						if(this.setBatchPhoneProducts  != null && this.setBatchPhoneProducts.length > 0){
							this.batchPhoneForm.discount = this.setBatchPhoneProducts[0].discount;
							//this.batchPhoneForm.deduct = this.setBatchPhoneProducts[0].deduct;
						}
					}
				});

       		}
            ,editBatchUpProduct(){
				if(this.setBatchProducts != null && this.setBatchProducts.length > 0 ){
					for(var i = 0 ; i < this.setBatchProducts.length ; i++){
						if(!this.setBatchProducts[i].productName || !this.setBatchProducts[i].productCode){
							this.$message({
								message: "产品编码错误,请检查,请输入上游提供的产品编码,如没有课填入对应的面值",
								type: 'error'
							});
							return;
						}
					}
					this.$refs.batchForm.validate((valid) => {
						if (valid) {
							this.$confirm('确认提交吗？', '提示', {}).then(() => {
								this.batchLoading = true;
							//NProgress.start();
							let para = Object.assign({}, this.batchForm);
							para.products = this.setBatchProducts;
							editBatchUpProduct(para).then((datas) => {
								this.batchLoading = false;
							let {message, code, data} = datas;
							if (code !== "0") {
								this.$message({
									message: message,
									type: 'error'
								});
							}else {
								if (code == "0") {
									this.$message({
										message: '操作成功',
										type: 'info'
									});
								}
							}
							this.findPageProduct();
						});
						});
						}
					});
				}else{
					this.$message({
						message: "请输入产品明细",
						type: 'error'
					});
				}
            },editProduct(){
                var temps = this.setBatchProducts;
				this.setBatchProducts = [];
                for(var cha in this.batchForm.channe){
                    for(var ch in this.channels){
                        if(this.channels[ch].basePrice+"" == this.batchForm.channe[cha]){
							var obj = new Object();
							obj.price = this.channels[ch].basePrice;
							obj.upfacevalue = this.channels[ch].flow;
							obj.discount = (this.channels[ch].flow * this.batchForm.unitPrice / this.channels[ch].basePrice).toFixed(5);
							obj.discountAmount = (this.channels[ch].flow * this.batchForm.unitPrice ).toFixed(5);
							const code = temps.find(item => {return item.price == this.channels[ch].basePrice});
							obj.productCode = code ? code.productCode : "";
							if(this.batchForm.provinceuuid){
								const result = this.info.find(item => { return item.provinceuuid == this.batchForm.provinceuuid });
								if(result){
									obj.productName = result.provincename + obj.upfacevalue+"元话费";
								}else{
									obj.productName = obj.upfacevalue+"元话费";
								}
							}else{
								obj.productName = obj.upfacevalue+"元话费";
							}
							if(temps.length > 0){
								const result = temps.find(item =>{ return item.upfacevalue == obj.upfacevalue});
								console.log(result)
								obj.upprouuid = result.upprouuid;
							}else{
								obj.upprouuid = this.channels[ch].upprouuid;
							}
							this.setBatchProducts.push(obj);
                        }
                    }
                }
            },batchCellclick:function(row, column, cell, event){
                if(column.label == "产品编码"){
                    var div = document.createElement("input");
                    div.value = cell.childNodes[0].innerHTML ;
                    div.style="height:32px;width:98px;"
                    cell.replaceChild(div,cell.childNodes[0]);
                    div.focus();
                }
                if(column.label == "产品名称"){
                    var div = document.createElement("input");
                    div.value = cell.childNodes[0].innerHTML ;
                    div.style="height:32px;width:98px;"
                    cell.replaceChild(div,cell.childNodes[0]);
                    div.focus();
                }
            },batchCellmouseleave:function(row, column, cell, event){
                if(column.label == "产品编码" && cell.childNodes[0].tagName.toLocaleLowerCase()=='input'){
                    var div = document.createElement("div");
                    div.setAttribute("class","cell");
                    div.innerHTML = cell.childNodes[0].value;
                    for(var pro in this.setBatchProducts){
                        if(this.setBatchProducts[pro].price == row.price && row.upfacevalue == this.setBatchProducts[pro].upfacevalue){
                            this.setBatchProducts[pro].productCode = cell.childNodes[0].value;
                        }
                    }
                    cell.replaceChild(div,cell.childNodes[0]);
                }
                if(column.label == "产品名称" && cell.childNodes[0].tagName.toLocaleLowerCase()=='input'){
                    var div = document.createElement("div");
                    div.setAttribute("class","cell");
                    div.innerHTML = cell.childNodes[0].value;
                    for(var pro in this.setBatchProducts){
                        if(this.setBatchProducts[pro].price == row.price && row.upfacevalue == this.setBatchProducts[pro].upfacevalue){
                            this.setBatchProducts[pro].productName = cell.childNodes[0].value;
                        }
                    }
                    cell.replaceChild(div,cell.childNodes[0]);
                }
            },handleBatchPhoneEdit:function(){
                if(this.filters.operatoruid == ""){
                    this.$message({
                        message: "请先选择运营商",
                        type: 'error'
                    });
                    return;
                }
                if(this.filters.provinceuuid == ""){
                    this.$message({
                        message: "请先选择省份",
                        type: 'error'
                    });
                    return;
                }
                if(this.filters.busuuid == "" ){
                    this.$message({
                        message: "请先选择业务类型",
                        type: 'error'
                    });
                    return;
                }
                if(this.filters.useruuid == ""){
                    this.$message({
                        message: "请先选择分销商",
                        type: 'error'
                    });
                    return;
                }
                this.setBatchPhoneProducts = [];
                this.findBatchUpProduct();
                this.batchPhoneFormVisible = true;
                this.batchPhoneForm.operatoruid = this.filters.operatoruid;
                this.batchPhoneForm.provinceuuid = this.filters.provinceuuid;
                this.batchPhoneForm.busuuid = this.filters.busuuid;
                this.batchPhoneForm.useruuid = this.filters.useruuid;
			},discountBatchPhoneChangeAdd:function(){
                var temps = this.setBatchPhoneProducts;
                for(var temp in temps){
                    temps[temp].discountAmount = ( temps[temp].price * this.batchPhoneForm.discount).toFixed(5);
                    temps[temp].deductAmount = ( temps[temp].price * this.batchPhoneForm.deduct).toFixed(5);
                    temps[temp].discount = (  this.batchPhoneForm.discount);
                    temps[temp].deduct = (  this.batchPhoneForm.deduct) ;
                }
			},editBatchPhoneUpProduct:function(){
                if(this.setBatchPhoneProducts != null && this.setBatchPhoneProducts.length > 0 ){
                    this.$refs.batchPhoneForm.validate((valid) => {
                        if (valid) {
                            this.$confirm('确认提交吗？', '提示', {}).then(() => {
                                this.batchLoading = true;
                                //NProgress.start();
                                let para = Object.assign({}, this.batchPhoneForm);
                                para.products = this.setBatchPhoneProducts;
                                editBatchPhoneUpProduct(para).then((datas) => {
                                    this.batchLoading = false;
                                    let {message, code, data} = datas;
                                    if (code !== "0") {
                                        this.$message({
                                            message: message,
                                            type: 'error'
                                        });
                                    }
                                    this.findPageProduct();
                                });
                            });
                        }
                    });
                }else{
                    this.$message({
                        message: "请输入产品折扣",
                        type: 'error'
                    });
                }
			},findAllCity:function (province) {
				let para = {
					province : province
				};
				findAllCity(para).then((datas) => {
					this.addLoading = false;
					let { message, code, data } = datas;
					if (code !== "0") {
						this.$message({
							message: message,
							type: 'error'
						});
					}

					this.infoFilters = [];
					this.citys = [];
					data.forEach((item,index) =>{
						this.citys.push({id:index,cityName:item});
						this.infoFilters.push({id:index,cityName:item});
					})
					this.editForm.cityName = data.cityName;
				});
			},selectCity(provinceuuid){
				const result = this.info.find(item => item.provinceuuid == provinceuuid);
				if(result){
					this.findAllCity(result.provincename)
				}
				if(provinceuuid ){
					if(this.setBatchProducts){
						const result = this.info.find(item => { return item.provinceuuid ==  provinceuuid});
						if(result){
							this.setBatchProducts.forEach( item =>{
								const face = item.productName.replace(/[^0-9]/ig,"");
								item.productName = result.provincename + face + "元话费";
							});
						}
					}
					if(this.setProducts){
						const result = this.info.find(item => { return item.provinceuuid ==  provinceuuid});
						if(result){
							this.setProducts.forEach( item =>{
								const face = item.productName.replace(/[^0-9]/ig,"");
								item.productName = result.provincename + face + "元话费";
							});
						}
					}
				}
			},selectfilter:function(row){
				this.filters.cityName = '';
				if(row != ""){
					this.findAllCity(row);
				}
			},
			changePressOrder(row){

				updateProductPressOrder(row).then((datas) => {
					let { message, code, data } = datas;
					if (code !== "0") {
						this.$message({
							message: message,
							type: 'error'
						});
					}
					this.findPageProduct();
				});
			},
			changeArtificial(row){

				updateProductArtificial(row).then((datas) => {
					let { message, code, data } = datas;
					if (code !== "0") {
						this.$message({
							message: message,
							type: 'error'
						});
					}
					this.findPageProduct();
				});
			},
			changeBatchPressOrder(form){
				console.log(form)
			},
			changeBatchArtificial(form){
				console.log(form)
			},
			deleteEnable(index,row){
				this.$confirm('确定删除产品吗?', '提示', {
					type: 'warning'
				}).then(() => {
					deleteUpProduct([row]).then(datas => {
						let {message, code, data} = datas;
						if (code !== "0") {
							this.$message({
								message: message,
								type: 'error'
							});
						} else {
							this.$message({
								message: "删除成功",
								type: 'info'
							});
						}
						this.findPageProduct();
					});
				}).catch(() => {

				});
			},
			findAllChannel(){
				let para = {
					province : ""
				};
				findAllChannel(para).then((datas) => {
					this.addLoading = false;
					let { message, code, data } = datas;
					if (code !== "0") {
						this.$message({
							message: message,
							type: 'error'
						});
					}else if(data){
						data.forEach(item =>{
							this.downfacevalues.push({id:item,value:item});
						});
					}
				});
			}
		},
		async mounted() {
			await this.findPageProduct();
		},
		async created(){
			await this.loadBasicInfo();
			await this.findAllUpShopInfo();
			await this.findAllChannel();
		}
	}

</script>

<style scoped>

</style>
